﻿<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <title>叩丁狼CRM(演示版)</title>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <#include "../common/head.ftl"/>
    <link rel="stylesheet" href="/css/core.css"/>
</head>
<body>
<#assign menu="department"/>
<div class="container " style="margin-top: 20px">
    <#include "../common/welcome.ftl"/>
    <div class="row">
        <#include "../common/menu.ftl"/>

        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">部门管理</h1>
                </div>
            </div>

            <form class="form-inline" id="searchForm" action="/department/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <a  class="btn btn-success input_btn">
                    <span class="glyphicon glyphicon-plus"></span> 添加
                </a>
            </form>

            <table class="table table-striped table-hover" >
                <tr>
                    <th>序号</th>
                    <th>部门名称</th>
                    <th>部门编号</th>
                    <th>操作</th>
                </tr>
                <#list pageInfo.list as entity >
                <tr>
                    <td>${entity_index + 1}</td>
                    <td>${entity.name}</td>
                    <td>${entity.sn}</td>
                     <td>
                         <a role="button" data-json='${entity.json}' class="btn btn-info btn-xs input_btn">
                             <span  class="glyphicon glyphicon-pencil"></span> 编辑
                         </a>
                         <a role="button" data-url="/department/delete.do?id=${entity.id}" class="btn btn-danger btn-xs delete_btn" >
                             <span class="glyphicon glyphicon-trash"></span> 删除
                         </a>

                     </td>
                </tr>
                </#list>
            </table>
            <#include "../common/page.ftl"/>
        </div>
    </div>
</div>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">部门编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/department/saveOrUpdate.do" method="post" id="editForm">
                    <input type="hidden" name="id">
                    <div class="form-group" >
                        <label class="col-sm-3 control-label">部门名称：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="name" placeholder="请输入部门名称">
                        </div>
                    </div>


                    <div class="form-group">
                        <label class="col-sm-3 control-label">部门编号：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="sn" placeholder="请输入部门编码">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary saveOrUpdate_btn">保存</button>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $(".input_btn").click(function () {
            var json = $(this).data("json");
            $("#editForm input").val("");
            if(json){
                $("#editForm input[name='id']").val(json.id);
                $("#editForm input[name='name']").val(json.name);
                $("#editForm input[name='sn']").val(json.sn);
            }
            $("#myModal").modal("show");
        });

        $(".saveOrUpdate_btn").click(function () {
            $("#editForm").submit();
        });

        //将同步表单换为异步表单
        $("#editForm").ajaxForm(function(data) {
            doSucceed();
        });

    });

</script>
<#include "../common/mycode.ftl"/>
</body>
</html>